/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.isfd.constant.enums;

import com.comac.ins.common.core.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * mongoDB查询条件枚举
 *
 * @author lj
 * @date 2025-01-13
 */
@AllArgsConstructor
@Getter
public enum IsfdMongoQueryOperatorEnum {
    EQUAL("eq", "等于"),
    NOT_EQUAL("ne", "不等于"),
    LESS_THAN("lt", "小于"),
    LESS_THAN_EQUALS("lte", "小于等于"),
    GREATER_THAN("gt", "大于"),
    GREATER_THAN_EQUALS("gte", "大于等于"),
    INCLUDES("in", "包含"),
    NOT_INCLUDES("nin", "不包含"),
    LIKE("like", "模糊匹配");

    private final String value;
    private final String desc;

    public static String getDescByValue(String value) {
        IsfdMongoQueryOperatorEnum isfdAnalysisApplicationTypeEnum = forValue(value);
        if (isfdAnalysisApplicationTypeEnum == null) {
            return null;
        }
        return isfdAnalysisApplicationTypeEnum.getDesc();
    }

    public static IsfdMongoQueryOperatorEnum forValue(String value) {
        if (StringUtils.isBlank(value)) {
            return null;
        }
        for (IsfdMongoQueryOperatorEnum isfdAnalysisApplicationTypeEnum : IsfdMongoQueryOperatorEnum.values()) {
            if (isfdAnalysisApplicationTypeEnum.getValue().equals(value)) {
                return isfdAnalysisApplicationTypeEnum;
            }
        }
        return null;
    }

    public static IsfdMongoQueryOperatorEnum forDesc(String desc) {
        if (desc == null) {
            return null;
        }
        for (IsfdMongoQueryOperatorEnum isfdAnalysisApplicationTypeEnum : IsfdMongoQueryOperatorEnum.values()) {
            if (desc.equals(isfdAnalysisApplicationTypeEnum.getDesc())) {
                return isfdAnalysisApplicationTypeEnum;
            }
        }
        return null;
    }
}
